#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1005;
const int INF = INT_MAX;
int n, k, a[N], q, x, l, r, ans, v;
bool vis[N],f = 0;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f*=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
inline int sub1(int l, int r, int v, int cnt){
//	cout << l << " " << r << " " << v << " " << cnt << endl;
	if(l == 1 && r == n) return cnt;
	if(v >= a[l - 1] && l != 1 && !vis[l - 1]) vis[l - 1] = 1, sub1(l - 1, r, v, cnt + 1);
	else if(v >= a[r + 1] && r != n && !vis[r + 1]) vis[r + 1] = 1, sub1(l, r + 1, v, cnt + 1);
	else sub1(l, r, min(a[l - 1], a[r + 1]), cnt + k);
}
signed main(){
	freopen("summer.in", "r", stdin);
	freopen("summer.out", "w", stdout);
	n = read(), k = read();
	for(int i = 1; i <= n; i++) a[i] = read();
	a[0] = a[n + 1] = INF;
	q = read();
	while(q--){
		ans = 0;
		x = read(), l = read(), r = read();
		swap(a[x], a[x + 1]);
		for(int i = l; i <= r; i++){
			memset(vis, 0, sizeof(vis));
			vis[i] = 1, ans = ans + sub1(i, i, a[i], 0);
		}	
		cout << ans << endl;
	}
	return 0;
}
/*
7 7
4 3 2 1 2 3 4
5
1 1 3
2 3 5
3 2 5
4 1 5
5 1 5
*/

